<?php

    namespace app\store\api;

    use app\common\controller\API;
    use app\store\model\GoodsModel;

    class Goods extends API
    {

        /**
         * 商品列表
         * api GET /store/goods/lists
         *
         * @param    array $category_id 分类ID
         *
         * @return array    $data    商品列表
         * @throws \think\exception\DbException
         */
        public function lists()
        {

            $goods_list = GoodsModel::lists();
            $this->result($goods_list);
        }

        /**
         * 商品详情
         * api GET /store/goods/detail
         *
         * @param    array $goods_id 商品ID
         *
         * @return array    $data    商品详情
         */
        public function detail()
        {

            $data = $this->request->param();
            $this->check_validate($data,'Goods.detail');
            $detail = GoodsModel::getDetail($data['goods_id']);

            $detail['image']  = get_file_path($detail['image']);
            $detail['images'] = get_files_path($detail['images']);

            $module_config = module_config('store');

            if ($module_config['store_price_view'] == GoodsModel::PRICE_VIEW_NOTHING)
            {
                unset($detail['price'],$detail['point']);
                $detail['company_title'] = '';
            }
            if ($module_config['store_price_view'] == GoodsModel::PRICE_VIEW_POINT)
            {
                unset($detail['price']);
                $detail['company_title'] = $detail['point'] . ' 积分/' . $detail['company'];
            }
            if ($module_config['store_price_view'] == GoodsModel::PRICE_VIEW_PRICE)
            {
                unset($detail['point']);
                $detail['company_title'] = $detail['price'] . ' 元/' . $detail['company'];
            }

            $this->result($detail);
        }
    }
